#include <REGX52.H>
#include "Delay.h"
#include "Nixie.h"
#include "Timer0.h"
#include "KeyTimer0.h"

sbit LED = P2^0;


unsigned char KeyNum_f,Speed = 0;
unsigned char Counter,Compare;//前者计数，后者作为比较变量

void main()
{
	Timer0_Init();
	
	while(1)
	{
		KeyNum_f = GetKey_Num();
		if(KeyNum_f == 1)
		{
			Speed++;
			if(Speed>=4) Speed = 0;
			if(Speed == 0){Compare=0;}
			if(Speed == 1){Compare=5;}
			if(Speed == 2){Compare=50;}
			if(Speed == 3){Compare=100;}
		}
		Nixie(0,Speed);
		
		
		
	}
	
}

void Timer0_Routine() interrupt 1  //定时器0的中断函数
{
	static unsigned int anjian;
	
	TL0 = 0xA4;		//100us进入一次
	TH0 = 0xFF;		
	Counter++;
	anjian++;
	if(anjian>=10)//10ms,扫描一次按键
	{
		KeyScan();
		anjian=0;
	}
	if(Counter >= 100) Counter = 0;
	if(Counter < Compare) {LED = 0;}
	else {LED = 1;}
}

